package com.ikkong.tfwSettings.controller;

import java.util.Map;
import com.ikkong.core.base.BaseController;
import com.ikkong.core.jfinal.ext.kit.JsonKit;
import com.ikkong.core.jfinal.ext.shiro.ClearShiro;
import com.ikkong.system.controller.base.UrlPermissController;
import com.ikkong.tfwSettings.model.TfwSettings;
import com.ikkong.tfwSettings.service.TfwSettingsService;
import com.ikkong.tfwSettings.service.impl.TfwSettingsServiceImpl;
import org.apache.shiro.authz.annotation.RequiresUser;

import static com.ikkong.system.util.CommonUtil.MES_TYPE;

/**
 * Generated by Blade.
 * 2020-02-03 15:56:39
 */
public class TfwSettingsController extends UrlPermissController {
	private static String CODE = "tfwSettings";
	private static String PERFIX = "tfw_settings";
	private static String LIST_SOURCE = "TfwSettings.list";
	private static String BASE_PATH = "/platform/tfwSettings/";
	
	TfwSettingsService service = new TfwSettingsServiceImpl();
	
	public void index() {
		setAttr("code", CODE);
		render(BASE_PATH + "tfwSettings.html");
	}

	public void add() {
		setAttr("code", CODE);
		render(BASE_PATH + "tfwSettings_add.html");
	}

    @ClearShiro
    @RequiresUser
	public void setType(){
        TfwSettings b = service.findById(3);
        String type = getPara("type", "type1");
        b.setContent(type);
        boolean update = service.update(b);
        if(update){
            MES_TYPE = type;
            renderJson(success("修改成功"));
        }else {
            renderJson(error("修改失败"));
        }
    }
	public void edit() {
		String id = getPara(0);
		TfwSettings tfwSettings = service.findById(id);
		setAttr("model", JsonKit.toJson(tfwSettings));
		setAttr("id", id);
		setAttr("code", CODE);
		render(BASE_PATH + "tfwSettings_edit.html");
	}

	public void view() {
		String id = getPara(0);
		TfwSettings tfwSettings = service.findById(id);
		setAttr("model", JsonKit.toJson(tfwSettings));
		setAttr("id", id);
		setAttr("code", CODE);
		render(BASE_PATH + "tfwSettings_view.html");
	}

	public void list() {
		Object grid = paginate(LIST_SOURCE);
		renderJson(grid);
	}

	public void save() {
		TfwSettings tfwSettings = mapping(PERFIX, TfwSettings.class);
		boolean temp = service.save(tfwSettings);
		if (temp) {
			renderJson(success(SAVE_SUCCESS_MSG));
		} else {
			renderJson(error(SAVE_FAIL_MSG));
		}
	}

	public void update() {
		TfwSettings tfwSettings = mapping(PERFIX, TfwSettings.class);
		boolean temp = service.update(tfwSettings);
		if (temp) {
			renderJson(success(UPDATE_SUCCESS_MSG));
		} else {
			renderJson(error(UPDATE_FAIL_MSG));
		}
	}

	public void remove() {
		String ids = getPara("ids");
		int cnt = service.deleteByIds(ids);
		if (cnt > 0) {
			renderJson(success(DEL_SUCCESS_MSG));
		} else {
			renderJson(error(DEL_FAIL_MSG));
		}
	}
}
